
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;

public class CollegeRegisterServlet extends HttpServlet
{
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {

     try
       {

         response.setContentType("text/html");

         PrintWriter out=response.getWriter();

        String college_name=request.getParameter("college_name");
        String university=request.getParameter("university");
        String college_code=request.getParameter("college_code");
        String college_uname=request.getParameter("college_uname");
        String college_pwd=request.getParameter("college_pwd");
	String phone_number=request.getParameter("phn_no");
        String email=request.getParameter("email") ;
        if((college_name !="") && (university !="") &&(college_code !="")&&(college_uname !="")&&(college_pwd !="")&&(phone_number !="")&&(email !=""))
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");

         Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","pac","mca"); 
 
         PreparedStatement pstmt1=con.prepareStatement("insert into college_login values(?,?)");
         
         pstmt1.setString(1,college_uname);
         pstmt1.setString(2,college_pwd);
       
         pstmt1.executeUpdate();


         PreparedStatement pstmt2=con.prepareStatement("insert into college_register values(?,?,?,?,?,?)");
         
         pstmt2.setString(1,college_name);
         pstmt2.setString(2,university);
         pstmt2.setString(3,college_code);
         
         pstmt2.setString(4,college_uname);
        
         pstmt2.setString(5,phone_number);
          pstmt2.setString(6,email);
         pstmt2.executeUpdate();


         out.println("<html>");
     
         out.println("<body background=\"t7.jpg\">");
 
         out.println("<font size=\"4\" color=\"white\">");
  
         out.println("<br> <b> Registered Successfully </b>");

         out.println("<br><br> <b> <a href=\"college-login.html\"> <font color=\"cyan\"> Click here </font> </a> to Login </b>");

         out.println("</font>");

         out.println("</body>");

         out.println("</html>");        
 
      }
        else
            out.println("Registration is failed due to invalid data");
       
  }
 
    catch(Exception e)
       {
         response.sendError(505,e.getMessage());
         e.printStackTrace();
       }    

  }

}  

 